// 格式化数字，保存小数点后两位数

export function formatNumber(num: string | number): string {
  if (typeof num === 'number') {
    return num.toFixed(2);
  }
  if (isNaN(Number(num))) {
    return '0.00';
  }
  const pointIndex: number = num.indexOf('.');
  if (pointIndex === -1) {
    return num + '.00';
  }
  if (num.length - pointIndex > 3) {
    return num.slice(0, pointIndex + 3);
  }
  switch (num.length - pointIndex) {
    case 1:
      return num + '00';
    case 2:
      return num + '0';
    default:
      return num;
  }
}
